package com.huike.common.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;
import java.util.List;


/**
 * 封装分页查询结果
 */
@Data

public class PageResult<T> implements Serializable {
    private Long total;//总记录数
    private T rows;//当前页结果
    private Integer code; //编码：200成功，500和其它数字为失败
    private String msg; //错误信息
    private String params;

    public static <T> PageResult<T> success(long total ,T object) {
        PageResult<T> pageResult = new PageResult<>();
        pageResult.code = 200;
        pageResult.msg = "查询成功";
        pageResult.total = total;
        pageResult.rows = object;
        return pageResult;
    }


    public static <T> PageResult<T> error(String msg) {
        PageResult result = new PageResult();
        result.msg = "查询失败";
        result.code = 500;
        return result;
    }
}
